package com.hp.attendance.service;

import com.hp.attendance.dao.HistoryDao;
import com.hp.attendance.entity.Employee;
import com.hp.attendance.entity.History;
import com.hp.attendance.entity.PageInfo;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class HistoryService {
    private HistoryDao historyDao = new HistoryDao();

    public PageInfo<History> getPage(int pageNo , int pageSize) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        PageInfo<History> page = new PageInfo<History>();
        //查询分页的数据                           2       10
        List<History> list = historyDao.getLimitList(pageNo, pageSize);
        page.setRecords(list);
        //查询总记录条数
        long total = historyDao.getTotal();
        page.setTotal(total);
        //设置当前页码
        page.setCurrent(pageNo);
        //设置总页数
        int pages = (int)Math.ceil(total / (pageSize * 1.0));
        page.setPages(pages);
        return page;
    }

    public History getHistory(int id) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        return historyDao.getHistory(id);
    }

    //修改员工信息
    public void historyUpdate(History history) throws SQLException, IOException, ClassNotFoundException {
        historyDao.historyUpdate(history);
    }

    public void historyUpdate1(History history) throws SQLException, IOException, ClassNotFoundException {
        historyDao.historyUpdate1(history);
    }

    //根据员工编号删除his表员工信息
    public void hisDelete(int employee_number) throws SQLException, IOException, ClassNotFoundException {
        historyDao.hisDelete(employee_number);
    }

    //在his表添加员工
    public void hisAdd(History history) throws SQLException, IOException, ClassNotFoundException {
        historyDao.hisAdd(history);
    }

    public List<History> getList() throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        return historyDao.getList();
    }
}
